package com.slliver.controller;

import com.slliver.pojo.Order;
import com.slliver.service.OrderService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RefreshScope // 使用post请求 http://localhost:7777/actuator/refresh 刷新配置中心配置
@RestController
@RequestMapping("/order")
public class OrderController {

    private final OrderService orderService;

    public OrderController(OrderService productService){
        this.orderService = productService;
    }


    @Value("${spring.profiles.active}")
    private String active;

    @Value("${spring.application.name}")
    private String name;


    @Value("${spring.datasource.password}")
    private String mysqlPassword;


    @GetMapping("/getName")
    public String info(){
        return "当前激活的配置环境是 ===>> " + active + ", 获取到当前应用的名称是 ===>> " + name + ", 获取的数据库连接密码 ===>>" + mysqlPassword;
    }

    @GetMapping("/get/{orderId}")
    public Order get(@PathVariable("orderId") Integer orderId){
        return orderService.getProductById(orderId);
    }
}
